<template>
  <div>
    <div class="banner-container">
      <img :src="bannerUrl" alt="" />
      <div class="banner-text">
        <div class="banner-text-title">模型广场</div>
        <div class="banner-text-desc">寻找喜爱的模型，直接开聊。</div>
      </div>
    </div>
    <!-- 筛选项 -->
    <div class="filter-wrapper">
        <div class="filter-title">模型分类</div>
        <div class="filter-tag-wrapper">
          <div 
            class="filter-tag-item" 
            v-for="item in modelTypeList" 
            :key="item" 
            :class="{ 'filter-tag-item-selected': currentModelType === item }"
            @click="handleSelectModelType(item)"
          >{{ item }}</div>
        </div>
    </div>
    <!-- 模型大全 -->
    <div class="model-grid-container">
      <div v-for="item in modelList" :key="item.id" class="model-card" @click="handleSelectModel(item)">
        <!-- 基本信息 -->
        <div class="model-card-info-warpper">
          <img :src="item.avatar" alt="" class="model-card-avatar" />
          <div class="info-detail-wrapper">
            <div class="model-card-name">{{ item.name }}</div>
            <div class="model-card-id">ID: {{ item.id }}</div>
          </div>
        </div>
        <!-- 模型卡片描述 -->
        <div class="model-card-desc">{{ item.systemPrompt }}</div>
        <!-- 模型卡片标签 -->
        <div class="model-card-tag-wrapper">
          <div class="tag-item">官方</div>
          <div class="tag-item">推荐</div>
          <div class="tag-item">不错</div>
        </div>
        <!-- 互动信息 -->
        <div class="interaction-wrapper">
          <div class="interaction-item">
            <UserOutlined />
            <span>1234</span>
          </div>
          <div class="interaction-item">
            <MessageOutlined />
            <span>2345</span>
          </div>
          <div class="interaction-item">
            <HeartOutlined />
            <span>325</span>
          </div>
          <div class="model-card-author">
            <div class="author-avatar">
              <img :src="bolatuAvatar" alt="" />
            </div>
            <span>理想国</span>
            <SafetyCertificateFilled clas style="color: #1677ff" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
// ------------ import ------------
import { reactive, ref, onMounted } from "vue";
import {
  UserOutlined,
  MessageOutlined,
  HeartOutlined,
  SafetyCertificateFilled,
} from "@ant-design/icons-vue";
import { getCharacters } from "~/api/chat";
import bolatuAvatar from "~/assets/role/bolatu_avatar.png";
// ------------ data ------------
const bannerUrl = "https://seven-cow.obs.cn-south-1.myhuaweicloud.com/banner/model_square_banner.png";
const modelList = reactive([]);
const modelTypeList = ref([
  '全部',
  '官方',
  '推荐',
  '最新发布',
  '专家',
  '历史',
  '娱乐',
  '职场'
]);
const currentModelType = ref('全部');
const router = useRouter();
// ------------ function ------------
const handleInit = async () => {
  // 初始化模型列表
  const res = await getCharacters();
  modelList.push(...res.data);
};

// 选择模型并跳转到聊天页面
const handleSelectModel = (model) => {
  router.push(`/myChat?id=${model.id}`);
};

// 选择模型类型
const handleSelectModelType = (type) => {
  currentModelType.value = type;
  // 这里可以添加根据类型筛选模型的逻辑
};

// ------------ onMounted ------------
onMounted(() => {
  handleInit();
});
</script>

<style lang="scss" scoped>
.banner-container {
  width: 100%;
  height: 400px;

  img {
    width: 100%;
    object-fit: cover;
  }

  .banner-text {
    position: absolute;
    top: 20%;
    left: 200px;
    color: rgba(8, 13, 30, 0.95);
    font-size: 60px;
    font-weight: normal;
    line-height: 80px;
    display: flex;
    flex-direction: column;

    &-title {
      font-family: "OPPOSans", sans-serif;
    }

    &-desc {
      font-family: "OPPOSans", sans-serif;
      font-size: 40px;
      line-height: 60px;
      color: rgba(8, 13, 30, 0.7);
    }
  }
}

// 筛选项
.filter-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 40px;
  margin-top: 20px;
  background-color: #fff;

  .filter-title {
    font-size: 20px;
    font-weight: bold;
  }

  .filter-tag-wrapper {
    display: flex;
    gap: 10px;
  }

  .filter-tag-item {
    padding: 10px 25px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #2029459e;
    

    &:hover {
      color: #5147ff;
      border: 1px solid #e4e7ff;
      background-color: #e4e7ff;
    }
    
    &.filter-tag-item-selected {
      color: #5147ff;
      background-color: #e4e7ff;
      font-weight: 500;
      border: 1px solid #5147ff;
    }
  }
}

.model-grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  grid-gap: 20px;
  padding: 20px 40px;

  // 模型卡片
  .model-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 400px;
    height: 230px;
    padding: 20px;
    border: 1px solid #ececec;
    border-radius: 8px;
    box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    cursor: pointer;

    &:hover {
      box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.15);
    }

    // 模型卡片基本信息
    .model-card-info-warpper {
      display: flex;
      gap: 20px;

      // 模型头像
      .model-card-avatar {
        width: 60px;
        height: 60px;
        border-radius: 8px;
      }

      // 模型卡片详细信息
      .info-detail-wrapper {
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
      }

      // 模型卡片名称
      .model-card-name {
        font-size: 24px;
        font-weight: bold;
      }

      // 模型卡片ID
      .model-card-id {
        font-size: 12px;
        color: #666;
      }
    }

    // 模型卡片描述
    .model-card-desc {
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
      font-size: 14px;
      color: #666;
      line-height: 1.5em;
      height: 3em;
    }

    // 模型卡片标签
    .model-card-tag-wrapper {
      display: flex;
      gap: 8px;
      font-size: 12px;
      color: #999;

      // 模型卡片标签项
      .tag-item {
        padding: 4px 8px;
        border-radius: 4px;
        background-color: #f3f3f3;
        cursor: pointer;
        transition: all 0.3s ease;

        &:hover {
          background-color: #e5e5e5;
        }
      }
    }

    // 模型卡片互动信息
    .interaction-wrapper {
      display: flex;
      align-items: center;
      gap: 16px;
      border-top: 1px solid #eee;
      padding-top: 16px;
      color: #bbb;
      font-size: 12px;
      margin-top: auto;

      // 模型卡片互动信息
      .interaction-item {
        display: flex;
        align-items: center;
        gap: 5px;
      }

      // 模型卡片作者
      .model-card-author {
        display: flex;
        align-items: center;
        height: fit-content;
        font-size: 12px;
        color: #999;
        gap: 5px;
        margin-left: auto;

        // 模型卡片作者头像
        .author-avatar {
          width: 20px;
          height: 20px;
          border-radius: 100%;
          overflow: hidden;

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
      }
    }
  }
}
</style>
